package cn.wolfcode.wolf2world.web.config;

import cn.wolfcode.wolf2world.resolver.UserArgumentResolver;
import cn.wolfcode.wolf2world.web.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @author 杨兴健
 * @Date 2020/8/9 19:15
 */
@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Autowired
    private UserArgumentResolver argumentResolver;
    /**
     * 注册拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/users/checkPhone")
                .excludePathPatterns("/users/regist")
                .excludePathPatterns("/users/login")
                .excludePathPatterns("/users/sendVerifyCode")
                .excludePathPatterns("/regist.html")
                .excludePathPatterns("/login.html");
    }

    /**
     * 注册处理器参数解析器
     * @param resolvers
     */
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(argumentResolver);
    }
}
